package org.mili.ticketeer.service;

import org.mili.ticketeer.dao.ContactDao;
import org.mili.ticketeer.dao.DaoFactory;
import org.mili.ticketeer.dao.ModificationResult;
import org.mili.ticketeer.dto.Contact;
import org.mili.ticketeer.util.Lambda;

import java.util.List;

public class ContactService extends Service {
	private ContactDao _contactDao = DaoFactory.getDao(ContactDao.class);

    public List<Contact> getContacts() throws ServiceException {
        return doReadInService(new Lambda<List<Contact>>() {
            @Override
            public List<Contact> exec(Object... params) throws Exception {
                return _contactDao.getContacts();
            }
        });
    }

    public ModificationResult write(final Contact contact) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return _contactDao.write(contact);
            }
        });
    }

    public ModificationResult delete(final Contact contact) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return _contactDao.delete(contact);
            }
        });
    }

    public Contact findByLastName(final String name) throws ServiceException {
        return doReadInService(new Lambda<Contact>() {
            @Override
            public Contact exec(Object... params) throws Exception {
                return _contactDao.findByLastName(name);
            }
        });
    }

    public List<Contact> getSpeakersSortedByStreetAndName() throws ServiceException {
        return doReadInService(new Lambda<List<Contact>>() {
            @Override
            public List<Contact> exec(Object... params) throws Exception {
                return _contactDao.getSpeakersSortedByStreetAndName();
            }
        });
    }
}
